/*
 * @Title Jfreechart.java
 * jfreechart-x.x.x.jar
 * jcommon-x.x.x.jar
 * @Copyright Copyright(c) 2018
 * @Company com.lizhen
 * @author lizhen
 * @version 0.0.1
 */
package com.lizhen.core.function.jfreechart;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

import javax.swing.*;

/**
 * @author lizhen
 */
public class Jfreechart {

    /**
     * @author lizhen
     */
    public Jfreechart() {
    }

    /**
     * @author lizhen
     */
    public static void main(String[] args) {
        JfreechartPie.main(null);
    }

    static class JfreechartPie extends ApplicationFrame {

        private static final long serialVersionUID = 1L;

        public JfreechartPie(String title) {
            super(title);
            setContentPane(createMobilePanel());
        }


        private static JFreeChart createChart(PieDataset dataset) {
            JFreeChart chart = ChartFactory.createPieChart("Mobile Sales", dataset, true, true, false);
            return chart;
        }

        private static PieDataset createDataset() {
            DefaultPieDataset dataset = new DefaultPieDataset();
            dataset.setValue("IPhone 5s", new Double(20));
            dataset.setValue("SamSung Grand", new Double(20));
            dataset.setValue("MotoG", new Double(40));
            dataset.setValue("Nokia Lumia", new Double(10));
            return dataset;
        }

        public static JPanel createMobilePanel() {
            JFreeChart chart = createChart(createDataset());
            return new ChartPanel(chart);
        }

        public static void main(String[] args) {
            JfreechartPie jfreechartPie = new JfreechartPie("Mobile Sales");
            jfreechartPie.setSize(560, 367);
            RefineryUtilities.centerFrameOnScreen(jfreechartPie);
            jfreechartPie.setVisible(true);
        }
    }

}


